package com.doudoukeji.service.Activity.my;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.doudoukeji.service.Activity.ConstantValue;
import com.doudoukeji.service.Bean.Token;
import com.doudoukeji.service.Http.MyHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.sanhai.android.mvp.BasePresenter;
import com.sanhai.android.service.http.BusinessClient;
import com.sanhai.android.service.http.FastHttpResponseHandler;
import com.sanhai.android.service.http.Response;

import org.apache.http.Header;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： MyPresenter
 * @包名称： com.doudoukeji.service.Activity.my
 * @创建人： zhanjunjie
 * @创建时间：2016/3/15 15:36
 * @修改人：
 * @修改时间：2016/3/15 15:36
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class MyPresenter extends BasePresenter {

    private MyView view;

    public MyPresenter(Context context, MyView view) {
        super(context, view);
        this.view = view;
    }

    public void getMyInfo() {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getId());
        params.put("token", Token.getToken());
        Log.d("aaaa", ConstantValue.myinfo + "?userId=" + Token.getId() + "&token=" + Token.getToken());
        BusinessClient.post(ConstantValue.myinfo, params, new MyHttpResponseHandler(view) {
            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    MyBean myBean = new MyBean();
                    myBean.setId(response.getString("id"));
                    myBean.setPhone(response.getString("phone"));
                    myBean.setName(response.getString("name"));
                    myBean.setHospitals(response.getString("hospitals"));
                    myBean.setServices(response.getString("services"));
                    myBean.setCodeImage(response.getString("codeImage"));
                    view.getMyInfo(myBean);
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getfail();
            }
        });
    }

    public void loginout(){
        RequestParams params = new RequestParams();
        params.put("userId",Token.getId());
        params.put("token",Token.getToken());
        BusinessClient.post(ConstantValue.loginout, params, new FastHttpResponseHandler() {
            @Override
            public void onResponse(Response response) {
                view.loginoutok();
            }
        });
    }

}
